using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace RapidHDL
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
    {
        private IO io1;
        private IO io2;
        private ChipConsole chipConsole1;
        private IO io3;
        private IO io4;
        private IO ioAddr;
        private IO ioData;
        private IO ioWrite;
        private IO ioStart;
        private Button button1;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form1()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            this.ioStart = new RapidHDL.IO();
            this.ioWrite = new RapidHDL.IO();
            this.ioData = new RapidHDL.IO();
            this.ioAddr = new RapidHDL.IO();
            this.io4 = new RapidHDL.IO();
            this.io3 = new RapidHDL.IO();
            this.chipConsole1 = new RapidHDL.ChipConsole();
            this.io2 = new RapidHDL.IO();
            this.io1 = new RapidHDL.IO();
            this.button1 = new System.Windows.Forms.Button();
            this.SuspendLayout();
            // 
            // ioStart
            // 
            this.ioStart.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.ioStart.Location = new System.Drawing.Point(532, 503);
            this.ioStart.Name = "ioStart";
            this.ioStart.Size = new System.Drawing.Size(238, 99);
            this.ioStart.TabIndex = 17;
            // 
            // ioWrite
            // 
            this.ioWrite.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.ioWrite.Location = new System.Drawing.Point(532, 398);
            this.ioWrite.Name = "ioWrite";
            this.ioWrite.Size = new System.Drawing.Size(238, 99);
            this.ioWrite.TabIndex = 16;
            // 
            // ioData
            // 
            this.ioData.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.ioData.Location = new System.Drawing.Point(270, 438);
            this.ioData.Name = "ioData";
            this.ioData.Size = new System.Drawing.Size(238, 99);
            this.ioData.TabIndex = 15;
            // 
            // ioAddr
            // 
            this.ioAddr.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.ioAddr.Location = new System.Drawing.Point(12, 438);
            this.ioAddr.Name = "ioAddr";
            this.ioAddr.Size = new System.Drawing.Size(238, 99);
            this.ioAddr.TabIndex = 14;
            // 
            // io4
            // 
            this.io4.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.io4.Location = new System.Drawing.Point(591, 12);
            this.io4.Name = "io4";
            this.io4.Size = new System.Drawing.Size(238, 99);
            this.io4.TabIndex = 13;
            // 
            // io3
            // 
            this.io3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.io3.Location = new System.Drawing.Point(305, 12);
            this.io3.Name = "io3";
            this.io3.Size = new System.Drawing.Size(238, 99);
            this.io3.TabIndex = 12;
            // 
            // chipConsole1
            // 
            this.chipConsole1.Location = new System.Drawing.Point(12, 137);
            this.chipConsole1.Name = "chipConsole1";
            this.chipConsole1.Size = new System.Drawing.Size(826, 295);
            this.chipConsole1.TabIndex = 11;
            this.chipConsole1.Load += new System.EventHandler(this.chipConsole1_Load);
            // 
            // io2
            // 
            this.io2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.io2.Location = new System.Drawing.Point(450, 12);
            this.io2.Name = "io2";
            this.io2.Size = new System.Drawing.Size(355, 99);
            this.io2.TabIndex = 1;
            this.io2.Visible = false;
            // 
            // io1
            // 
            this.io1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.io1.Location = new System.Drawing.Point(22, 12);
            this.io1.Name = "io1";
            this.io1.Size = new System.Drawing.Size(238, 99);
            this.io1.TabIndex = 0;
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(257, 12);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(42, 61);
            this.button1.TabIndex = 18;
            this.button1.Text = "button1";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // Form1
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(846, 611);
            this.Controls.Add(this.button1);
            this.Controls.Add(this.ioStart);
            this.Controls.Add(this.ioWrite);
            this.Controls.Add(this.ioData);
            this.Controls.Add(this.ioAddr);
            this.Controls.Add(this.io4);
            this.Controls.Add(this.io3);
            this.Controls.Add(this.chipConsole1);
            this.Controls.Add(this.io2);
            this.Controls.Add(this.io1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

        MyHardware oHardware;

        private void Form1_Load(object sender, EventArgs e)
        {
            //MessageBox.Show(FPGATest.IOTestMessage("CFBase.bit", 184549376, 1000));
            //return;
            oHardware = new MyHardware();

            chipConsole1.AttachRapidHardware(oHardware);

            io1.AssignSignal(oHardware, "enable", true, false);
            io2.AssignSignal(oHardware, "counter.reset_to.and0.Out", false, true);
            io3.AssignSignal(oHardware, "Go", true, false);
            io4.AssignSignal(oHardware, "Finish", true, false);

            ioAddr.AssignSignal(oHardware, "SysDataIn", true, false);
            ioData.AssignSignal(oHardware, "SysAddress", true, false);
            ioWrite.AssignSignal(oHardware, "SysStart", true, false);
            ioStart.AssignSignal(oHardware, "SysWrite", true, false);

            //io3.AssignSignal(oHardware, "counter.adder.InA", false, true);
            //io4.AssignSignal(oHardware, "counter.adder.InB", false, true);
            //io5.AssignSignal(oHardware, "counter.adder.Out", false, true);
            //io6.AssignSignal(oHardware, "counter.CountOut", false, true);

            oHardware.StartRapidHardware();
            chipConsole1.ShowTranscript();
        }

        private void chipConsole1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            FSignals frmSignals = new FSignals();
            frmSignals.Initialize(oHardware);
            frmSignals.Show();
        }


	}
}
